// index.js
// 获取应用实例
import request from '../../utils/http.js'
const app = getApp()

Page({
  data: {

    swiperHeight: 0,
    currentTab: 0,

    IsLogin: false,
    shopName: '',
    dianPuId: 0, //当前店铺ID
    tjr_id: 0,
    isscene: false, //判断是否扫码进来的

    JKQName: '',
    niCheng: '注册会员',
    phone: '',
    name: '',
    touXiangUrl: '/image/touxiang_no.png',
    personId: 0,
    tjr_id: 0,

    zhiWei: '',
    zhiWeiRole: 0,
    huiYuanRoleStr: '',
    huiYuanRole: 0, //1会员 2会长 3总裁

    nextJinDu: 0,
    nextRenShu: 0,
    nextHuiYuanRoleStr: '',
    nextHuiYuanRole: 0,


    image1: 'https://insurancecard.oneplusyang.com/20240325084325c652a8801f5c456a9d3685a8633f3f76.png',
    image2: 'https://insurancecard.oneplusyang.com/202403221752263a4b7ef194b64e97a2e84f63d25d2250.png',
    image3: 'https://insurancecard.oneplusyang.com/20240322180641e3383a5e73904ee5b3e484bf5f5e085a.png',
    image4: 'https://insurancecard.oneplusyang.com/2024032218060345a67867cbfb4373ad6aa8cf7c3df365.png',

    // fengcaiList:[],
    // fengcaiLength:0,
    // baoMinList:[],
    // baoMinLength:0,


    verIndex: 2,
  },


  //启动加载
  onLoad: function (options) {
    // console.log("首页传参数:" + JSON.stringify(options))

    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          swiperHeight: res.windowHeight - app.globalData.CustomBar - 10
        });
      }
    });


    that.setData({
      IsLogin: options.dianPuId > 0 ? false : wx.getStorageSync(app.globalData.LOGINSTATUS),
      dianPuId: (options.dianPuId == '' || options.dianPuId == undefined) ? (wx.getStorageSync(app.globalData.SHOPID) > 0 ? wx.getStorageSync(app.globalData.SHOPID) : 1) : options.dianPuId,
      tjr_id: (options.tjr_id == '' || options.tjr_id == undefined) ? wx.getStorageSync(app.globalData.TJR_ID) : options.tjr_id,
      personId: wx.getStorageSync(app.globalData.PERSON_ID)
    })


    if (options.scene) { //海报扫码
      let scene = decodeURIComponent(options.scene);
      that.setData({
        IsLogin: false,
        dianPuId: scene.split("_")[0],
        tjr_id: scene.split("_")[1],
        isscene: true
      })
    }


    // console.log("dianPuId2:"+that.data.dianPuId)

    wx.setStorageSync(app.globalData.SHOPID, that.data.dianPuId)
    wx.setStorageSync(app.globalData.TJR_ID, that.data.tjr_id)
    wx.setStorageSync(app.globalData.LOGINSTATUS, that.data.IsLogin)

    that.getShoppingInfo();
    that.getVersion();
    // if(that.data.IsLogin){
    //   that.gethyInfo()
    // }

  },

  onShow: function () {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1
      })
    }

    this.setData({
      IsLogin: wx.getStorageSync(app.globalData.LOGINSTATUS),
      tjr_id: wx.getStorageSync(app.globalData.TJR_ID),
      personId: wx.getStorageSync(app.globalData.PERSON_ID)
    })

    // console.log("aaaa=="+app.globalData.shopIsChange)

    if (app.globalData.shopIsChange) {
      this.setData({
        dianPuId: wx.getStorageSync(app.globalData.SHOPID)
      })

    }

    if (this.data.IsLogin) {
      this.gethyInfo()
    }
  },


  //获取店铺信息
  getShoppingInfo: function () {

    var that = this

    let data = {
      dianPuId: that.data.dianPuId
    }
    request.get('dianPu/basicInfo', data, res => {
      // console.log("店铺信息:" + JSON.stringify(res.data))
      that.setData({
        shopName: res.data.mingCheng,
        JKQName: res.data.jianKangQuanMingCheng,
        // diZhi: res.data.diZhi,
        // dianPuId: res.data.dianPuId,
        // dianPuLeiXing: res.data.dianPuLeiXing,
        // dianPuLeiXingStr:res.data.dianPuLeiXingStr,
        // dianPuBianHao:res.data.dianPuBianHao,
      })

      wx.setStorageSync(app.globalData.SHOPID, res.data.dianPuId)
      wx.setStorageSync(app.globalData.ShopName, res.data.mingCheng);
      wx.setStorageSync(app.globalData.ShopLogo, res.data.logo)
      wx.setStorageSync(app.globalData.JKQName, res.data.jianKangQuanMingCheng)

    }, err => {
      wx.showToast({
        title: '获取信息失败', // 提示的内容
        icon: "none", // 图标，默认success
        duration: 1000, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿透
      })
    })

  },

  //获取会员信息
  gethyInfo: function () {
    var that = this
    let data = {
      dianPuId: that.data.dianPuId
    }
    request.get('person/getPersonJianKangHui', data, res => {

      console.log("会员信息:" + JSON.stringify(res.data))
      // wx.setStorageSync(app.globalData.VerIndex, res.data.status)
      that.setData({

        phone: res.data.phone,
        name: res.data.name,
        touXiangUrl: res.data.touXiangUrl,
        niCheng: res.data.niCheng,
        huiYuanRole: res.data.huiYuanRole,
        huiYuanRoleStr: res.data.huiYuanRoleStr,
        nextHuiYuanRoleStr: res.data.nextHuiYuanRoleStr,
        nextHuiYuanRole: res.data.nextHuiYuanRole,
        nextRenShu: res.data.nextRenShu,
        nextJinDu: res.data.nextJinDu,
        zhiWei: res.data.zhiWei,
        zhiWeiRole: res.data.zhiWeiRole

      })

    }, err => {

    })
  },

  //获取审核状态
  getVersion: function () {
    var that = this
    let data = {
      version: app.globalData.version
    }
    request.get('version/getVersionStaus', data, res => {

      // console.log("getVersionStaus:" + JSON.stringify(res.data))
      wx.setStorageSync(app.globalData.VerIndex, res.data.status)
      that.setData({
        verIndex: res.data.status
      })

    }, err => {

    })
  },

  //注册页面
  tozhuce() {
    wx.navigateTo({
      url: '/pages/hy_zhuce/hy_zhuce',
    })
  },

  tozhucePross() {
    wx.navigateTo({
      url: '/pages/zhucePross/zhucePross',
    })
  },

  tozhuceVido() {
    wx.navigateTo({
      url: '/pkg_index/pages/zhuceVido/zhuceVido',
    })
  },

  //会员产品选择
  tohy_Product() {
    wx.navigateTo({
      url: '/pkg_index/pages/hy_product/hy_product',
    })

  },

  //权益查看跳转
  quanyitap() {
    wx.navigateTo({
      url: '/pages/quanyi/quanyi?dianPuId=' + this.data.dianPuId,
    })
  },



  //歌曲制作需求
  toMusicInfo() {
    if (this.data.huiYuanRole > 0) {
      wx.navigateTo({
        url: '/pkg_index/pages/hy_musicInfo/hy_musicInfo',
      })
    } else {
      wx.showToast({
        title: '成为会员即可定制专属歌曲哦~', // 提示的内容
        icon: "none", // 图标，默认success
        duration: 3000, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿透
      })
    }


  },

  //分红测算
  toCeSuan() {

    // if (this.data.huiYuanRole > 0 || this.data.zhiWeiRole > 0) {
      wx.navigateTo({
        url: '/pkg_index/pages/cesuan/cesuan?dianPuId=' + this.data.dianPuId,
      })
    // } else {
    //   wx.showToast({
    //     title: '成为会员才可以查看哦~', // 提示的内容
    //     icon: "none", // 图标，默认success
    //     duration: 3000, // 提示的延迟时间，默认1500
    //     mask: false, // 是否显示透明蒙层，防止触摸穿透
    //   })
    // }

    // wx.showToast({
    //   title: '即将发布', // 提示的内容
    //   icon: "none", // 图标，默认success
    //   duration: 3000, // 提示的延迟时间，默认1500
    //   mask: false, // 是否显示透明蒙层，防止触摸穿透
    // })

  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    // console.log('pp' + this.data.fenXiangPicUrl)
    return {
      title: this.data.JKQName,
      imageUrl: 'https://insurancecard.oneplusyang.com/2024032516561414849efa435c4506bd94a86a88d75601.png',
      path: '/pages/index_jk/index_jk?tjr_id=' + this.data.personId + '&dianPuId=' + this.data.dianPuId
    }
  },

})